﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Biz.Buffer;
using Biz.EF.Platform.SG;
using Hjt212Parser;
using log4net;

namespace Biz.Process
{
   public static class ProcessorHelper
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(ProcessorHelper));

        public static bool IsLossInfoOfCmd(string content, out string mn, out DateTime? datatime, out 企业排口 port, out List<string> codes)
        {
            datatime = null;
            port = null;
            codes = null;

            mn = Parser.GetStringByKey("MN", content);
            if (string.IsNullOrWhiteSpace(mn))
            {
                Log.Warn("MN 为空.");
                return true;
            }

            datatime = Parser.GetDateTimeByKey("DataTime", content);
            if (!datatime.HasValue)
            {
                Log.Warn("DataTime 为空.");
                return true;
            }

            port = CommonInformation.GetLetportByMn(mn);
            if (port == null)
            {
                Log.Warn("MN：" + mn + " 找不到对应企业排口!");
                return true;
            }

            codes = Parser.GetPollutantCodes(content);
            if (codes == null)
            {
                Log.Warn("没有污染物因子.");
                return true;
            }

            return false;
        }


        public static bool IsMasterCode(string code)
        {
            return ";w00000;a00000;B01;B02;".Contains(";" + code + ";");
        }

        public static void RemoveMasterFactor(List<string> codes, bool indeed)
        {
            if (!indeed) return;

            codes.Remove("B01");
            codes.Remove("w00000");
            codes.Remove("B02");
            codes.Remove("a00000");
        }
    }
}
